$(function(){
    var footer_offset = $("footer").offset()
    var r = Math.floor(Math.random()*180+20)
    var g = Math.floor(Math.random()*180+20)
    var b = Math.floor(Math.random()*180+20)
    $(".bg").css({
        "top" : footer_offset.top-$(".bg").height()+"px",
        "width" : $(".content_main").width()+$("#bg1").width()+$("#bg2").width()+"px",
        "margin-left" : "-"+($(".content_main").width()+$("#bg1").width()+$("#bg2").width())/2-47+"px"
    });

    $('.sidebar').animate({
        left: '0'},
        300, function() {
            $(this).animate({
                left: '-220px',},
                300, function() {
                $(this).animate({
                    left: '-200px',},
                    150, function() {
                    /* stuff to do after animation is complete */
                });
            });
    });
    $(window).resize(function(event) {
        $(".bg").css({
        "top" : footer_offset.top-$(".bg").height()+"px",
        "width" : $(".content_main").width()+$("#bg1").width()+$("#bg2").width()+"px",
        "margin-left" : "-"+($(".content_main").width()+$("#bg1").width()+$("#bg2").width())/2-47+"px"
        });
    });
    /*alert(r+":"+g+":"+b)*/
    $(".header").css({
        "background-color" : "rgb"+"("+r+","+g+","+b+")"
    })
    $("footer").css({
        "background-color" : "rgb"+"("+r+","+g+","+b+")"
    })
    /*锚点平滑过渡*/
    $(".jump").click(function () {
        $('html, body').animate({
            scrollTop: $($.attr(this,'href')).offset().top
        }, 700);
        return false;
    });
    $(".logo").click(function(event) {
        $('.search_box').css({
            display: 'flex',
        });
        $('.search_bg').animate({
            width: '100%',
            height: '100%',
            opacity: '.99',
        },300,
        function() {
            $(this).animate({
                width: '95%',
                height: '98%'
            },
            150, function() {
                $(this).animate({
                    width: '100%',
                    height: '100%'},
                    50, function() {
                    /* stuff to do after animation is complete */
                });
            });
        });
    });
    $(".search_box_off").click(function(event) {
        $('.search_box').animate({
            'opacity': '0',
        },300,
        function() {
            $('.search_box').css({
                'display': 'none',
                'opacity': '1',
            });
            $('.search_bg').css({
                width: '0%',
                height: '0%',
            });
        });
    });
});